package org.ielts.domain.security;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.ielts.domain.base.Campus;
import org.ielts.domain.base.Department;
import org.ielts.domain.base.Teaching;

import com.yifeng.dto.Atom;

@Entity
@Table(name = "Users")
public class User extends com.yifeng.security.users.User {

	@Id
	@GeneratedValue(generator = "atomIdGenerator")
	@GenericGenerator(name = "atomIdGenerator", strategy = "uuid")
	protected String id;
	protected String name;
	protected String title;

	private String loginName;

	private String password;
	@ManyToMany()
	private Set<Role> roles = new HashSet<Role>();
	private Date createTime;
	@ManyToOne(fetch = FetchType.EAGER)
	private Department department;
	private Date entryTime;
	private String no;
	@ManyToOne(fetch = FetchType.EAGER)
	private Campus campus;

	@OneToMany(mappedBy = "teacher")
	private Set<Teaching> teachings = new HashSet<Teaching>(0);

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj instanceof User) {
			if (this.getId() == null) {
				return false;
			}
			return this.getId().equals(((User) obj).id);
		}

		return false;
	}

	@Override
	public int hashCode() {
		if (this.id == null) {
			return 0;
		}
		return this.id.hashCode();
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Department getDepartment() {
		return department;
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public Date getEntryTime() {
		return entryTime;
	}

	public void setEntryTime(Date entryTime) {
		this.entryTime = entryTime;
	}

	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public Campus getCampus() {
		return campus;
	}

	public void setCampus(Campus campus) {
		this.campus = campus;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public Set<Teaching> getTeachings() {
		return teachings;
	}

	public void setTeachings(Set<Teaching> teachings) {
		this.teachings = teachings;
	}
}
